//
//  UIBarButton_Extension.swift
//  ZYDY
//
//  Created by zhangchao on 2017/8/17.
//  Copyright © 2017年 zhangchao. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(imageName : String, highImageName : String?, size : CGSize, target : AnyObject?, action: Selector?) {
        let btn = UIButton(type:.custom)
        btn.setImage(UIImage.init(named: imageName), for: .normal)
        btn.setImage(UIImage.init(named: imageName), for: .highlighted)
        if size == CGSize.zero {
            btn.sizeToFit()
        } else {
            btn.frame = CGRect.init(origin: CGPoint.init(x: 0, y: 0), size: size)
        }
        if action != nil {
            btn.addTarget(target, action: action!, for: .touchUpInside)
        }
        self.init(customView: btn)
    }
}
